package com.niguang.labour.admin.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.niguang.labour.admin.TeamListVo;
import com.niguang.labour.admin.entity.WorkTeamUser;
import com.niguang.labour.admin.mapper.WorkTeamUserMapper;
import com.niguang.labour.admin.service.WorkTeamUserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.niguang.labour.common.constant.ResultCode;
import com.niguang.labour.common.pojo.Result;
import com.niguang.labour.common.util.ApiTokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 'work.v_personSite' is not BASE TABLE 服务实现类
 * </p>
 *
 * @author
 * @since 2018-06-10
 */
@Service
public class WorkTeamUserServiceImpl extends ServiceImpl<WorkTeamUserMapper, WorkTeamUser> implements WorkTeamUserService {

    @Autowired
    private ApiTokenUtils apiTokenUtils;

    @Override
    public Result getTeamList(Page<TeamListVo> page, Long siteId) {
        List<TeamListVo> teamList = baseMapper.getTeamList(page, siteId, apiTokenUtils.getUserId());
        Map<String, Object> map = new HashMap<>(4);
        page.setRecords(teamList);
        map.put("total", page.getTotal());
        map.put("list", page.getRecords());
        map.put("pages", page.getPages());
        map.put("current", page.getCurrent());
        return Result.build(ResultCode.SUCCESS, "班组列表查询成功！", map);
    }

    @Override
    public Result getTeamSetUser(String siteId) {
        List<Map<String, Object>> mapList = baseMapper.getTeamSetUser(siteId, apiTokenUtils.getUserId());
        return Result.build(ResultCode.SUCCESS, "项目列表查询成功！", mapList);
    }

    @Override
    public Result getTeamListUser(Page<Map<String, Object>> page, String teamId) {
        List<Map<String, Object>> teamListUser = baseMapper.getTeamListUser(page, teamId);
        Map<String, Object> map = new HashMap<>(4);
        page.setRecords(teamListUser);
        map.put("total", page.getTotal());
        map.put("list", page.getRecords());
        map.put("pages", page.getPages());
        map.put("current", page.getCurrent());
        return Result.build(ResultCode.SUCCESS, "班组列表成功！", map);
    }
}
